import React from 'react';
import { connect } from 'umi';
import { Form, Modal, Radio, Row, Col } from 'antd';
import { QuickForm } from 'vv-frontend-components';

const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 }
};

const addConfig = () => [
    {
        field: 'candidateState',
        label: '筛选结果',
        key: 'candidateState',
        props: {
            ...formItemLayout
        },
        component: (
            <Radio.Group>
                <Radio value="pass">通过</Radio>
                <Radio value="eliminated">淘汰</Radio>
            </Radio.Group>
        ),
        config: {
            // initialValue: postDetail.postType ? postDetail.postType : [],
            rules: [{ required: true, message: '请设置筛选结果' }]
        }
    }
];
const SetResult = ({
    Visible,
    params,
    onOk,
    onCancel,
    dispatch,
    form
}) => {
    const { candidateCode, fetchList } = params;
    // 提交设置结果
    const handleOk = closeModel => {
        form.validateFields((err, values) => {
            if (!err) {
                dispatch({
                    type: 'common/setResult',
                    payload: {
                        ...values,
                        candidateCode
                        // id: postId
                    },
                    success: () => {
                        fetchList({ pageNo: 1 });
                    }
                });

                // 关闭模态框
                closeModel();
                form.resetFields();
            }
        });
    };
    return (
        <Modal
            title="设置筛选结果"
            width="750px"
            visible={Visible}
            // confirmLoading={loading}
            onOk={() => {
                handleOk(onOk);
            }}
            onCancel={() => {
                form.resetFields();
                onCancel();
            }}
        >
            {/* <Spin spinning={loading}> */}
            <Form layout="horizontal">
                <QuickForm config={addConfig()} form={form} />
                <Row>
                    <Col span={6}></Col>
                    <Col span={14}>
                        注：选择筛选结果后，系统将会更新筛选状态。
                    </Col>
                </Row>
            </Form>
            {/* </Spin> */}
        </Modal>
    );
};

export default connect(({ common, loading }) => ({
    common,
    loading
}))(Form.create()(SetResult));
